{% extends "../base.html" %}

{% block title %}Tasks{% endblock %}
{% block header %}Tasks - {{ project.name }}({{ project.creator.nickname }}){% endblock %}

{% block content %}
    <a href="/projects">Projects</a>
    <!-- <a href="/editProjectForm?projectId={{ project.key }}">Project</a> -->
	<div style="float:right">
	    <form style="display: inline" method="get" action="/tasks" id="search-form">
	    	<!-- {% if assignedToMe %}
	    	<input type="hidden" name="assignedToMe" id="assignedToMe" value="1"></input>
	    	{% endif %}	
	    	
	    	{% if my %}
	    	<input type="hidden" name="createdByMe" id="createdByMe" value="1"></input>
	    	{% endif %}	
	    	 -->
	    	<input type="hidden" name="projectId" id="projectId" value="{{ project.key }}"></input>
	    	
	    	Status:
	    	<select id="status" name="status" onchange="document.getElementById('search-form').submit()">
	    		<option value="">All</option>
	    		<option {% ifequal status 'CREATED' %}selected="selected"{% endifequal %}>CREATED</option>
	    		<option {% ifequal status 'ACCEPTED' %}selected="selected"{% endifequal %}>ACCEPTED</option>
	    		<option {% ifequal status 'SUSPENDED' %}selected="selected"{% endifequal %}>SUSPENDED</option>
	    		<option {% ifequal status 'RESUMED' %}selected="selected"{% endifequal %}>RESUMED</option>
	    		<option {% ifequal status 'FINISHED' %}selected="selected"{% endifequal %}>FINISHED</option>
	    		<option {% ifequal status 'CANCELLED' %}selected="selected"{% endifequal %}>CANCELLED</option>
	    	</select>
	    	
	    	<span class="leftSpaced">
		    	Created by me: 
		    	<input onchange="document.getElementById('search-form').submit()" type="checkbox" name="createdByMe" id="createdByMe" {% if my %}checked="checked"{% endif %}></input>
			</span>
			
	    	<span class="leftSpaced">
		    	Assigned to me: 
		    	<input onchange="document.getElementById('search-form').submit()" type="checkbox" name="assignedToMe" id="assignedToMe" {% if assignedToMe %}checked="checked"{% endif %}></input>
	    	</span>
	    	<input type="hidden" id="current" name="current" value="{{ current }}"></input>
	    	<input type="hidden" id="pageSize" name="pageSize" value="{{ pageSize }}"></input>
	    	
	    </form>
   	    {% if canEditProject %}
   	    	<a class="leftSpaced" href="/editProjectForm?projectId={{ project.key }}" style="font-weight: bold">Settings</a>
	    {% endif %} 
	    
	</div>
    

    <table cellpadding="0" cellspacing="0" class="list">
	    <thead>
	    	<th width="0%">No</th>	
	    	<th width="40%">Name</th>	
	    	<th width="15%">Created at</th>	
	    	<th width="10%">Created by</th>	
	    	<th width="10%">Assigned to</th>	
	    	<th width="10%">Status</th>	
	    	<th width="0%">Priority</th>	
	    	<th width="0%">Action</th>	
	    </thead>
    {% for task in tasks %}
        <tr style="
        	background-color: 
        	{% ifequal task.status 'CREATED'%}#FFFFFF
        	{% else %}
	        	{% ifequal task.status 'ACCEPTED' %}#DDFFDD
				{% else %}
					{% ifequal task.status 'SUSPENDED' %}#EEEEEE
					{% else %}
						{% ifequal task.status 'RESUMED' %}#DDFFDD
						{% else %}
							{% ifequal task.status 'CANCELLED' %}#FFEEEE
							{% else %}
								{% ifequal task.status 'FINISHED' %}#EEFFFF
								{% endifequal %}
							{% endifequal%}
						{% endifequal%}
					{% endifequal %}
				{% endifequal%}
        	{% endifequal %}
        "> 
            <form method="post" action="/deleteTask" id="delete-form-{{ task.key }}">
                <input type="hidden" name="taskId" value="{{ task.key }}"></input>
            </form>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.index }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.name }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.createdAt.day }}.{{ task.createdAt.month }}.{{ task.createdAt.year }} {{ task.createdAt.hour }}:{{ task.createdAt.minute }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.creator.nickname }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.assignedTo.user.nickname }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">{{ task.status }}</a></td>
            <td><a href="/editTask?taskId={{ task.key }}">
            	{% ifequal task.priority 0 %}Low{% endifequal %}
            	{% ifequal task.priority 1 %}Medium{% endifequal %}
            	{% ifequal task.priority 2 %}High{% endifequal %}
            </a></td>
            <td><a href="#" onclick="document.getElementById('delete-form-{{ task.key }}').submit()">Delete</a></td>
            
        </tr>
    {% endfor %}
    </table>
    
    <a href="/createTask?projectId={{ project.key }}">Add task</a>
    
    <span style="float:right">
        
        Count of tasks:<span style="font-weight: bold">{{ count }}</span>
        
        <span class="leftSpaced">
	        Select page size:
	        <select onchange="document.getElementById('pageSize').value=this.value  ; document.getElementById('search-form').submit()">
	        	<option {% ifequal pageSize 5 %} selected="selected" {% endifequal %}>5</option>
	        	<option {% ifequal pageSize 10 %} selected="selected" {% endifequal %}>10</option>
	        	<option {% ifequal pageSize 15 %} selected="selected" {% endifequal %}>15</option>
	        	<option {% ifequal pageSize 20 %} selected="selected" {% endifequal %}>20</option>
	        	<option {% ifequal pageSize 25 %} selected="selected" {% endifequal %}>25</option>
	        	<option {% ifequal pageSize 30 %} selected="selected" {% endifequal %}>30</option>
	        </select>
        </span>
        <span class="leftSpaced">
	        {% if not isFirstPage %}
		    <a href="#" onclick="document.getElementById('current').value={{ current }} - {{ pageSize }}; document.getElementById('search-form').submit()">Newer</a>
		    {% endif %}
        </span>
        <span class="leftSpaced">
		    {% if not isLastPage %}
		    <a href="#" onclick="document.getElementById('current').value={{ current }} + {{ pageSize }}; document.getElementById('search-form').submit()">Older</a>
		    {% endif %}
        </span>
    </span>
    
{% endblock %}
